#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/8/1 19:17
# @Author  : huidong.bai
# @File    : LCSService.py
# @Software: PyCharm
# @Mail    : MasterBai2018@outlook.com

import time
from ctypes import *
from conftest import logging


class LCSService:
    m_library = None
    m_lib_path = None

    def __init__(self, lib_path: str):
        self.m_lib_path = lib_path
    
    def load_lib(self):
        try:
            self.m_library = cdll.LoadLibrary(self.m_lib_path)
        except Exception as e:
            logging.error(f"Load lcs server library error: {e}")


    def start(self, config: str, lang: str) -> int:
        if (not config) or (not lang):
            logging.error(f"Init lcs server failed, config: {config}, lang: {lang}")
            return -2

        ret = self.m_library.start_LCSServer_service(config.encode('utf-8'), lang.encode('utf-8'))

        if ret == 0:
            logging.info('Init lcs server success.')
            return 0
        else:
            logging.error(f'Init lcs server error! ret: {ret}')
            return -2

    def stop(self) -> int:
        ret = self.m_library.stop_LCSServer_service()
        return ret
